package networkListener;

/**
 * @author re0hg
 * @version 1.0
 * @date 2025/3/28
 */

import java.io.FileWriter;
import java.io.IOException;
import java.util.Arrays;

public class CsvLogger {

    private static final String FILE_PATH = "ftp_login_data.csv";

    public void logToCsv(String timestamp, String[] packetData) {
        try (FileWriter writer = new FileWriter(FILE_PATH, true)) {
            if (new java.io.File(FILE_PATH).length() == 0) {
                writer.append("Timestamp,Source MAC,Source IP,Destination MAC,Destination IP,Username,Password,Status\n");
            }
            writer.append(String.join(",", timestamp, packetData[0], packetData[1], packetData[2], packetData[3], packetData[4], packetData[5], packetData[6]));
            writer.append("\n");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

}